package com.hy.mydesktop.client.component.factory;

import com.google.gwt.user.client.ui.SuggestBox;
import com.hy.mydesktop.client.component.meta.SuggestBoxModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
/**
 * 
 * <ul>
 * <li>开发作者：冬超</li>
 * <li>设计日期：2010-8-29；时间：下午04:13:18</li>
 * <li>类型名称：SuggestBoxFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class SuggestBoxFactory {
	public static SuggestBox createTabPanel(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {

		return configureSuggestBox(gxtComponentMetaNodeModel);

	}

	/**
	 * 
	 * 
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static SuggestBox configureSuggestBox(
			GxtComponentMetaNodeModel gxtComponentMetaNodeModel) {

		SuggestBox box = createDefaultSuggestBox();
		
		if (gxtComponentMetaNodeModel.get(SuggestBoxModelEnum.ANIMATIONENABLED.name()
				.toLowerCase()) != null) {
			Boolean enabled = (Boolean) gxtComponentMetaNodeModel
					.get(SuggestBoxModelEnum.ANIMATIONENABLED.name().toLowerCase());
			box.setAnimationEnabled((boolean)enabled);

		} 
		if (gxtComponentMetaNodeModel.get(SuggestBoxModelEnum.HIGHT
				.name().toLowerCase()) != null) {
			String height = (String) gxtComponentMetaNodeModel
					.get(SuggestBoxModelEnum.HIGHT.name().toLowerCase());
			box.setHeight(height);

		}
		if (gxtComponentMetaNodeModel.get(SuggestBoxModelEnum.LIMIT
				.name().toLowerCase()) != null) {
			Integer limit = (Integer) gxtComponentMetaNodeModel
					.get(SuggestBoxModelEnum.LIMIT.name().toLowerCase());
			box.setLimit((int)limit);

		}
		if (gxtComponentMetaNodeModel.get(SuggestBoxModelEnum.WIDTH
				.name().toLowerCase()) != null) {
			Integer width = (Integer) gxtComponentMetaNodeModel
					.get(SuggestBoxModelEnum.WIDTH.name().toLowerCase());
			box.setLimit((int)width);

		}
		if (gxtComponentMetaNodeModel.get(SuggestBoxModelEnum.TEXT
				.name().toLowerCase()) != null) {
			String text = (String) gxtComponentMetaNodeModel
					.get(SuggestBoxModelEnum.TEXT.name().toLowerCase());
			box.setText(text);

		}
		return box;
	}

	private static SuggestBox createDefaultSuggestBox() {

		SuggestBox box = new SuggestBox();
		return box;
	}
}
